Allow dynamic quota creation and removal#287
Allow dynamic quota creation and removal#287QuanMPhm wants to merge 1 commit intonerc-project:mainfrom
Conversation
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/calculate_storage_gb_hours.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py
Outdated
Show resolved
Hide resolved
b3c58d8 to
35273aa
Compare
|
@knikolla I addressed all your suggestions on Slack except one:
May I ask that I implement this feature in a subsequent PR, to prevent this PR from bloating even more? If not, I will implement this after I receive answers for my questions above. |
|
What is the impact of this omission? |
|
@joachimweyl The impact will be that to change the display names of attributes (the names that users will see in the Coldfront UI, i.e |
|
Makes sense to me. |
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_openshift_resource.py
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_openshift_resource.py
Outdated
Show resolved
Hide resolved
35273aa to
01021dd
Compare
src/coldfront_plugin_cloud/management/commands/remove_quota_from_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/remove_quota_from_resource.py
Outdated
Show resolved
Hide resolved
01021dd to
0cf04ea
Compare
src/coldfront_plugin_cloud/management/commands/add_openshift_resource.py
Outdated
Show resolved
Hide resolved
0cf04ea to
0c68d91
Compare
|
@knikolla @naved001 This PR is waiting on review. This is my last question |
src/coldfront_plugin_cloud/management/commands/register_default_quotas.py
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/register_default_quotas.py
Show resolved
Hide resolved
knikolla
left a comment
There was a problem hiding this comment.
Good work! I think this will be ready with a few minor iterations mostly related to fetching rate data from invoicing and some polish here and there.
I'll do a deeper pass in the afternoon but I don't expect anything big to jump out. Again, good work!
src/coldfront_plugin_cloud/management/commands/calculate_storage_gb_hours.py
Outdated
Show resolved
Hide resolved
12789b2 to
29ff0dc
Compare
|
@knikolla @naved001 I have responded to all comments so far. In response to this comment, I decided to use |
knikolla
left a comment
There was a problem hiding this comment.
Looks good, some questions.
src/coldfront_plugin_cloud/management/commands/register_default_quotas.py
Show resolved
Hide resolved
src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py
Show resolved
Hide resolved
|
Adding copilot to check if I missed something. If there's valid feedback I will tag you on the relevant comments. |
There was a problem hiding this comment.
Pull request overview
This PR moves quota definitions from hard-coded mappings into per-resource, dynamically managed quota specs stored on the resource, and updates allocators/tasks/commands/tests to consume those specs. It adds management commands to register defaults and to add/remove quotas on a resource so quotas can evolve without code changes.
Changes:
- Introduce
QuotaSpec/QuotaSpecsmodels and load quota specs from a resource attribute (Available Quota Resources) in allocators. - Add management commands to register default quotas and to add/remove quota specs on a resource.
- Refactor OpenShift/OpenStack allocators,
tasks.activate_allocation, allocation validation, and storage billing to use resource-defined quota specs; update functional/unit tests accordingly.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coldfront_plugin_cloud/tests/unit/test_usage_models.py | Update imports for moved usage_models. |
| src/coldfront_plugin_cloud/tests/unit/test_register_default_quotas.py | New unit tests for register_default_quotas behavior/idempotency. |
| src/coldfront_plugin_cloud/tests/unit/test_fetch_daily_billable_usage.py | Update imports for moved usage_models. |
| src/coldfront_plugin_cloud/tests/unit/test_calculate_quota_unit_hours.py | Ensure test resources have quota specs via add_quota_to_resource. |
| src/coldfront_plugin_cloud/tests/unit/openshift/test_rbac.py | Switch to shared unit OpenShift base allocator. |
| src/coldfront_plugin_cloud/tests/unit/openshift/base.py | Add mock allocator wrapper to avoid real allocator initialization dependencies. |
| src/coldfront_plugin_cloud/tests/functional/openstack/test_allocation.py | Adjust tests to rely on registered default quotas and resource quota specs. |
| src/coldfront_plugin_cloud/tests/functional/openshift_vm/test_allocation.py | Register defaults and customize VM GPU quotas via add/remove quota commands. |
| src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py | Register defaults and expand tests around adding/removing quotas dynamically. |
| src/coldfront_plugin_cloud/tests/functional/esi/test_allocations.py | Set up ESI quota specs dynamically in test setup. |
| src/coldfront_plugin_cloud/tests/base.py | Update OpenShift resource creation signature (internal_name) and remove IBM storage flag. |
| src/coldfront_plugin_cloud/tasks.py | Replace hard-coded quota math with QuotaSpec-driven computation. |
| src/coldfront_plugin_cloud/openstack.py | Replace static quota mappings with resource-defined quota specs grouped by service. |
| src/coldfront_plugin_cloud/openshift_vm.py | Remove VM-specific hard-coded quota mapping in favor of resource-defined specs. |
| src/coldfront_plugin_cloud/openshift.py | Remove hard-coded quota mapping; format quotas via resource-defined specs. |
| src/coldfront_plugin_cloud/models/usage_models.py | New module for pydantic usage/charges models (moved from old location). |
| src/coldfront_plugin_cloud/models/quota_models.py | New pydantic models for quota specs and validation. |
| src/coldfront_plugin_cloud/management/commands/validate_allocations.py | Validate allocations based on per-resource quota specs rather than hard-coded mappings. |
| src/coldfront_plugin_cloud/management/commands/remove_quota_from_resource.py | New command to remove a quota spec from a resource. |
| src/coldfront_plugin_cloud/management/commands/register_default_quotas.py | New command to populate default quota specs onto OpenShift/OpenStack resources. |
| src/coldfront_plugin_cloud/management/commands/fetch_daily_billable_usage.py | Update imports for moved usage_models. |
| src/coldfront_plugin_cloud/management/commands/calculate_storage_gb_hours.py | Drive storage billing from resource quota specs of type storage. |
| src/coldfront_plugin_cloud/management/commands/add_quota_to_resource.py | New command to add a quota spec to a resource and create its allocation attribute type. |
| src/coldfront_plugin_cloud/management/commands/add_openshift_resource.py | Remove IBM storage attribute wiring; add internal cluster name support. |
| src/coldfront_plugin_cloud/esi.py | Remove ESI hard-coded quota mapping in favor of inherited dynamic behavior. |
| src/coldfront_plugin_cloud/base.py | Load QuotaSpecs from resource attribute in allocator initialization. |
| src/coldfront_plugin_cloud/attributes.py | Replace IBM storage availability attribute with Available Quota Resources; adjust registered allocation quota attributes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/coldfront_plugin_cloud/tests/functional/openstack/test_allocation.py
Outdated
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/remove_quota_from_resource.py
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/remove_quota_from_resource.py
Show resolved
Hide resolved
src/coldfront_plugin_cloud/management/commands/calculate_storage_gb_hours.py
Show resolved
Hide resolved
Allocation quota attributes are no longer hardcoded in `attributes.py` and instead are created dynamically based on the quotas defined for each resource. This eliminates the need to modify code and restart the Coldfront service to update quotas. 3 new commands are added to implement this feature: - `add_quota_to_resource`: Adds a quota to a resource. - `remove_quota_from_resource`: Removes a quota from a resource. - `register_default_quotas`: Registers default quotas for all resources based a predetermined list These commands will interact with a new resource attribute `Available Quota Resources`, which stores a list of all quota resources that can be applied to a resource. When a quota is added or removed using the above commands, this attribute will be updated accordingly. Refactored various files to support dynamic quotas Updated functional and unit tests
|
Updated commit message |
Closes nerc-project/operations#1391. This is how I would suggest to review this PR.
Two CLI commands have been added,
add_quota_to_resource.pyandremove_quota_from_resource.py. I would suggest understanding those two commands first. These commands allow us to dynamically add/remove quotas instead of having them hard-coded as they are currently done. These commands don't impact the quota objects in the clusters, nor the quota attributes in allocations. Their full impact is illustrated when used within the typical user workflow, or in tandem withvalidate_allocations.py. I would now suggest checking the changes tofunctional/openshift/test_allocations.pyto see the full implications of this PR. The other functional test cases only contain minor changes.Afterwards,
tasks.py,validate_allocations.py, and the allocator base and subclasses should be reviewed. They are the main consumers of quota information. All other changes relatively minor.Follow-up issues to write based on these comments:
openshift vm quotas
idempotency for
register_default_quotasstorage billing
Clean-up hard-coded attributes